package com.situ.student.service.impl;

import java.util.List;

import com.situ.student.dao.IBanjiDao;
import com.situ.student.dao.impl.BanjiDaoImpl;
import com.situ.student.entity.Banji;
import com.situ.student.entity.PageBean;
import com.situ.student.entity.Student;
import com.situ.student.service.IBanjiService;

public class BanjiServiceImpl implements IBanjiService {
	private IBanjiDao banjiDao = new BanjiDaoImpl();
	private Banji banji;

	@Override
	public List<Banji> list() {
		return banjiDao.list();
	}

	@Override
	public boolean deleteById(Integer id) {
		int count = banjiDao.deleteById(id);
		return count == 1 ? true : false;
	}

	@Override
	public boolean insert(Banji banji) {
		int count = banjiDao.insert(banji);
		return count == 1 ? true : false;
	}

	@Override
	public Banji findById(Integer id) {
		return banjiDao.findById(id);
	}

	@Override
	public boolean update(Banji banji) {
		int count = banjiDao.update(banji);
		return count == 1 ? true : false;
	}

	@Override
	public PageBean getPageBean(int pageNo, int pageSize) {
		PageBean pageBean = new PageBean();
		// 当前是第几页
		pageBean.setPageNo(pageNo);
		// 一页有多少数据
		pageBean.setPageSize(pageSize);
		// 总记录数
		int totalCount = banjiDao.getTotalCount();
		pageBean.setTotalCount(totalCount);
		// 一共有多少页(向上取整，不满三条也算一页)
		int totalpage = (int) Math.ceil((double) totalCount / pageSize);
		pageBean.setTotalPage(totalpage);
		// 当前页的数据
		int offset = (pageNo - 1) * pageSize;// (limit第一个数据)
		List<Banji> list = banjiDao.pageList(offset, pageSize);
		pageBean.setList(list);

		return pageBean;

	}
}
